#include "Mover.h"




Mover::Mover (sf::Vector2f position, sf::Vector2f target, float offset, float speed, Artman *artman)
{
	this->setPosition(position);
	m_points[0]=position;
	m_points[1]=target;
	m_speed=speed;
	this->setTexture(*artman->getTexture("platform.png"));
	this->setTextureRect(sf::Rect<int>(0,0,this->getTexture()->getSize().x,this->getTexture()->getSize().y));
	this->setOrigin(this->getTexture()->getSize().x/2,this->getTexture()->getSize().y/2);
	m_velocity=target-position;
	m_distance=std::sqrt((std::abs(m_velocity.x)*std::abs(m_velocity.x))+(std::abs(m_velocity.y)*std::abs(m_velocity.y)));
	m_velocity=m_velocity/(m_distance/m_speed);
	m_time=(m_distance/m_speed);
	m_time=m_time-offset;
	this->setPosition(this->getPosition()+(m_velocity*offset));
	
}

void Mover::Update(float dt)
{
	
	this->setPosition(this->getPosition()+(m_velocity*dt));

	m_time-=dt;

	if (m_time<=0)
	{
		m_time=(m_distance/m_speed);
		m_velocity.x*=-1;
		m_velocity.y*=-1;
	}
	
}